#include<stdio.h>
#include<unistd.h>
#include<sys/types.h>
#include<stdlib.h>
#include<sys/wait.h>
int main(){

    pid_t id = fork();
    if(id == 0){
        int cnt = 5;
        while(1){
            printf("我是子进程，我的pid是：%d，cnt：%d\n",getpid(),cnt--);
            sleep(1);
            int*p = NULL;
            *p = 100;
            if(cnt == 0)exit(12);
        }
    }

    sleep(10);
    int status = 0;
    pid_t ret = waitpid(id,&status,0);
    if(ret>0){

         if(WIFEXITED(status)){
            printf("exit code: %d\n",WEXITSTATUS(status));
        }
        else{
            printf("出现异常\n");
        }
        //printf("ret:%d,status:%d,code:%d,signal:%d\n",ret,status,(status>>8)&0xFF,status&0x7F);
    }
    return 0;
}
